@using Variant = MudBlazor.Variant
@using Elsa.Api.Client.Resources.WorkflowActivationStrategies.Models
@using Elsa.Api.Client.Resources.IncidentStrategies.Models

@if (WorkflowDefinition != null)
{
    <div>
        <MudText Typo="Typo.overline">Settings</MudText>
        <MudStack Spacing="3">
            <MudSelect
                T="WorkflowActivationStrategyDescriptor"
                Label="Activation strategy"
                Variant="@Variant.Outlined"
                Value="@_selectedActivationStrategy"
                ToStringFunc="@(x => x?.DisplayName ?? string.Empty)"
                ValueChanged="@OnActivationStrategyChanged"
                HelperText="@(_selectedActivationStrategy?.Description)"
                ReadOnly="IsReadOnly">
                @foreach (var strategy in _activationStrategies)
                {
                    <MudSelectItem T="WorkflowActivationStrategyDescriptor" Value="@strategy">@strategy.DisplayName</MudSelectItem>
                }
            </MudSelect>
            <MudSelect
                T="IncidentStrategyDescriptor"
                Label="Incident handling strategy"
                Variant="@Variant.Outlined"
                Value="@_selectedIncidentStrategy"
                ToStringFunc="@(x => x?.DisplayName ?? "Default")"
                ValueChanged="@OnIncidentStrategyChanged"
                HelperText="@(_selectedIncidentStrategy?.Description)"
                ReadOnly="IsReadOnly">
                @foreach (var strategy in _incidentStrategies)
                {
                    <MudSelectItem T="IncidentStrategyDescriptor" Value="@strategy">@(strategy?.DisplayName ?? "Default")</MudSelectItem>
                }
            </MudSelect>
            <MudField Variant="Variant.Text" HelperText="Allow this workflow to be used as an activity." Margin="Margin.None">
                <MudCheckBox
                    T="bool?"
                    Label="Usable as activity"
                    Checked="@(WorkflowDefinition.Options.UsableAsActivity == true)"
                    CheckedChanged="@OnUsableAsActivityCheckChanged"
                    Dense="                    true"
                    ReadOnly="                    IsReadOnly"/>
            </MudField>
            @if (WorkflowDefinition.Options.UsableAsActivity == true)
            {
                <MudField Variant="Variant.Text" HelperText="When you publish a new version, all of the consuming workflows will be updated to point to the new version of this workflow." Margin="Margin.None">
                    <MudCheckBox
                        T="bool?"
                        Label="Auto-update consuming workflows"
                        Dense="@true"
                        Checked="@(WorkflowDefinition.Options.AutoUpdateConsumingWorkflows)"
                        CheckedChanged="@OnAutoUpdateConsumingWorkflowsCheckChanged"
                        ReadOnly="                        IsReadOnly"/>
                </MudField>
                <MudTextField
                    T="string"
                    Variant="Variant.Outlined"
                    Label="Category"
                    HelperText="A custom activity category to assign this workflow-as-an-activity to."
                    Value="@WorkflowDefinition.Options.ActivityCategory"
                    ValueChanged="OnCategoryChanged"/>
            }
        </MudStack>
    </div>
}